using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using Konst3d.Efficiency.Suite;

namespace Konst3d.Efficiency.Suite.SparsedBinary
{
    internal interface ICountDownTimerStorage
    {
        void UpdateTitle       (int id, string title);
        void UpdateDescription (int id, string description);
        void UpdateTargetDate  (int id, DateTime targetDate);
    }

    internal class CountDownTimer: ICountDownTimer
    {
        #region ICountDownTimer Members

        public int ID
        {
            get
            {
                return _id;
            }
        }

        public string Title
        {
            get
            {
                return _title;
            }
            set
            {
                _storage.UpdateTitle(_id, value);
                _title = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                _storage.UpdateDescription(_id, value);
                _description = value;
            }
        }

        public DateTime TargetDate
        {
            get
            {
                return _target;
            }
            set
            {
                _storage.UpdateTargetDate(_id, value);
                _target = value;
            }
        }

        public DateTime Created
        {
            get
            {
                return _created;
            }
        }

        public TimeSpan TimeLeft
        {
            get
            {
                return _target - DateTime.Now;
            }
        }

        #endregion

        #region Constructor

        public CountDownTimer(ICountDownTimerStorage storage, int id, string title, string description, DateTime target, DateTime created)
        {
            Contract.Requires(storage != null);

            _storage = storage;
            _id = id;
            _title = title;
            _description = description;
            _target = target;
            _created = created;
        }

        #endregion // Constructor

        #region Fields

        private ICountDownTimerStorage _storage;
        private int _id;
        private string _title;
        private string _description;
        private DateTime _target;
        private DateTime _created;

        #endregion // Fields
    }
}
